package com.study.www.demofilter.web;

import com.alibaba.fastjson.JSONObject;
import com.study.www.demo.Application;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : Administrator.zhuyanpeng
 * @date : 2019/11/15 - 16:52
 */
@Slf4j
@RequestMapping("/demo2")
@RestController
public class Demo2Controller {

    @GetMapping("/getTest/{id}")
    public JSONObject getTest(@PathVariable String id){
        log.warn("Demo2Controller 的 getTest ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",DemoController.map.get(id));
        return jsonObject;
    }

    @PutMapping("/putTest/{value}")
    public JSONObject putTest(@PathVariable String value){
        log.warn("Demo2Controller 的 putTest ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
        DemoController.map.put(DemoController.map.size()+"",value);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code","0");
        return jsonObject;
    }
}
